<?php

namespace app\adminapi\controller\merchant;

use app\adminapi\controller\BaseAdminController;
use app\adminapi\http\middleware\MerchantMiddleware;
use app\adminapi\lists\CardLists;
use app\common\model\Card;
use app\common\model\Merchant;
use app\common\model\WithdrawOrder;

class CardController extends BaseAdminController
{
    protected $middleware = [
        MerchantMiddleware::class,
    ];


    public function lists()
    {
        return $this->dataLists(new CardLists(['merchant_id' => $this->request->merhchant_id]));
    }

    public function count()
    {
        $data = [
            'card_total'  => Card::where('merchant_id', $this->request->merhchant_id)->count(),
            'card_used'   => Card::where('merchant_id', $this->request->merhchant_id)->where('status', 1)->count(),
            'card_unused' => Card::where('merchant_id', $this->request->merhchant_id)->where('status', 0)->count(),
            'commission'  => Merchant::where('id', $this->request->merhchant_id)->value('commission'),
            'withdraw_unapply'    => WithdrawOrder::where('merchant_id', $this->request->merhchant_id)->where('status',0)->sum('amount'),
            'withdraw_pass'      => WithdrawOrder::where('merchant_id', $this->request->merhchant_id)->where('status',1)->sum('amount'),
            'withdraw_refuse'     => WithdrawOrder::where('merchant_id', $this->request->merhchant_id)->where('status',-1)->sum('amount'),

        ];
        return $this->success('', $data);
    }

}